package com.framework.bas.util.linq;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LinqTest {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		List testList = new ArrayList();
		testList.add(new JsTreeItem(1, "cui", null));
		testList.add(new JsTreeItem(2, "cui1", new JsTreeItem(6, "cui6", null)));
		testList.add(new JsTreeItem(3, "cui2", null));
		testList.add(new JsTreeItem(4, "cui3", null));
		testList.add(new JsTreeItem(5, "cui4", null));
		
		testList = new Linq().from(testList).addFilter(new EqFilter("item.text","cui6")).addFilter(new EqFilter("id","2")).list();
		
		System.out.println(testList);
		
		testList.clear();
		Map map = new HashMap();
		map.put("id", 1);
		map.put("text", "cui");
		map.put("item", 1);
		testList.add(map);
		map = new HashMap();
		map.put("id", 2);
		map.put("text", "cui1");
		map.put("item", 1);
		testList.add(map);
		map = new HashMap();
		map.put("id", 3);
		map.put("text", "cui2");
		map.put("item", 1);
		testList.add(map);
		map = new HashMap();
		map.put("id", 4);
		map.put("text", "cui3");
		map.put("item", 1);
		testList.add(map);
		map = new HashMap();
		map.put("id", 5);
		map.put("text", "cui4");
		map.put("item", 1);
		testList.add(map);
		map = new HashMap();
		map.put("id", 6);
		map.put("text", "cui5");
		map.put("item", 1);
		testList.add(map);
		
//		testList = new Linq().from(testList).addFilter(new EqFilter("text","cui5")).addFilter(new EqFilter("id","6")).list();
		testList = new Linq().from(testList).addFilter(new IFilter<Map>() {
			public boolean filter(ILinq linq,Map obj) {
				if((Integer)obj.get("id") > 3){
					return true;
				}
				return false;
			}
		}).addFilter(new EqFilter("text", "cui5")).list();
		
		System.out.println(testList);
		
	}
	public static class JsTreeItem {
		private int id;
		private String text;
		private JsTreeItem item;
		
		
		public JsTreeItem(int id, String text, JsTreeItem item) {
			super();
			this.id = id;
			this.text = text;
			this.item = item;
		}
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public String getText() {
			return text;
		}
		public void setText(String text) {
			this.text = text;
		}
		public JsTreeItem getItem() {
			return item;
		}
		public void setItem(JsTreeItem item) {
			this.item = item;
		}
		@Override
		public String toString() {
			return "JsTreeItem [id=" + id + ", item=" + item + ", text=" + text + "]";
		}
	}
}
